using System;
using System.Collections.Generic;
using BitMango; 
using Data;
using UnityEngine;

public class Director : SingletonMonoBehaviour<Director>
{
    private void OnGUI()
    {
        GUI.Label(new Rect(0f, 0f, 1f, 1f), string.Empty);
    }

    protected override void Awake()
    {
        SingletonMonoBehaviour<LevelSetRoot>.Instance.SetDataset();
        Platform.Init();
        //if (!UncleBill.IsRich)
        //{
        //    Context.AdManager.Run(273);
        //    if (Context.BMPlatform.isFirstRun)
        //    {
        //        Context.AdManager.SkipInterstitial(120f);
        //    }
        //}
        base.Awake();
        if (!base.IsValid())
        {
            return;
        }
        //string str = "_private";
        //string apiurl = "http://playtomic.bitmango.com:3000/";
        //Playtomic.Initialize(Context.BMPlatform.appID, Context.BMPlatform.appID + str, apiurl);
    }

    private void Update()
    {
        OverlayQue.Process();
    }

    private void Start()
    {
        Handheld.StopActivityIndicator();
        Input.multiTouchEnabled = false;
        Application.targetFrameRate = 60;
        Scene.EnableAndroidEscapeEvent = true;
        Scene.ChangeTo("IntroScene", null);
        this.bgmName = "bg_play_classic";
        this.BGMSetting();
        this.SFXSetting();
        DWATTLight.logEvent("LoadCompleteTime", new object[]
        {
            Time.realtimeSinceStartup.ToString(),
            "OUT"
        });
        Wallet.itemChangedCallback += this.OnChangedItem;
        if (Platform.CheckAndFixedFirebase)
        {
            string userId = "bhp.logid." + Profile.ADID;
        }
        Context.AdManager.OnClosed += this.OnCloseAd;
    }

    private void OnCloseAd(AdManager.AdType type)
    {
        if (type == AdManager.AdType.INTERSTITIAL || type == AdManager.AdType.VIDEO)
        {
            Context.AdManager.BannerReload();
        }
    }

    public void BGMSetting()
    {
        if (DataContainer<Data.Root>.Data.options.record.bgm)
        {
            BMSoundHelper.PlayBGM(this.bgmName, 0, true, true);
        }
        else
        {
            BMSoundHelper.StopBGM(0, true, 0.5f);
        }
    }

    public void SFXSetting()
    {
        this.volumeRate = ((!DataContainer<Data.Root>.Data.options.record.sfx) ? 0f : 1f);
    }

    private void SetLevelNumber()
    {
        foreach (Package package in DataContainer<Data.Root>.Data.packages)
        {
            for (int j = 0; j < package.levels.Length; j++)
            {
                package.levels[j].num = j;
            }
        }
    }

    private void OnChangedItem(InventoryItem item, int count)
    {
        //if (UncleBill.IsRich)
        //{
        //    Context.AdManager.Stop();
        //    if (BannerAnchor.BannerActive)
        //    {
        //        BannerAnchor.BannerActive = false;
        //    }
        //}
        //else if (!BannerAnchor.BannerActive)
        {
            BannerAnchor.BannerActive = true;
        }
    }

    private void OnApplicationPause(bool paused)
    {
        if (paused)
        {
            BlockAlarm.RegisterAlarm();
            DWATTHelper.logEvent("RemainCoin", new object[]
            {
                Wallet.GetItemCount("blockcoin").ToString()
            });
        }
    }

    private void OnApplicationQuit()
    {
        BlockAlarm.RegisterAlarm();
    }

    public void TopOverlayEnable(bool isEnable)
    {
        this.topOverlay.SetActive(isEnable);
    }

    public void AppsFlyerLogEvent(string eventName)
    {
        if (PlayerPrefs.GetInt(eventName, 0) == 0)
        {
            PlayerPrefs.SetInt(eventName, 1);
        }
    }

    public GameObject topOverlay;

    private bool sendTokenToAppsFlyer;

    public static bool isShowReviewPopup;

    [HideInInspector]
    public float volumeRate;

    [HideInInspector]
    public string bgmName = "bg_play_classic";
}
